package edu.scau.mis.cloth.service.impl;

import edu.scau.mis.cloth.entity.GsClothes;
import edu.scau.mis.cloth.entity.GsReturn;
import edu.scau.mis.cloth.dao.GsReturnDao;
import edu.scau.mis.cloth.service.GsReturnService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (GsReturn)表服务实现类
 *
 * @author makejava
 * @since 2022-05-02 16:18:33
 */
@Service("gsReturnService")
public class GsReturnServiceImpl implements GsReturnService {
    @Resource
    private GsReturnDao gsReturnDao;

    /**
     * 通过ID查询单条数据
     *
     * @param returnId 主键
     * @return 实例对象
     */
    @Override
    public GsReturn queryById(Integer returnId) {
        return this.gsReturnDao.queryById(returnId);
    }

    /**
     * 分页查询
     *
     * @param gsReturn 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GsReturn> queryByPage(GsReturn gsReturn, PageRequest pageRequest) {
        long total = this.gsReturnDao.count(gsReturn);
        return new PageImpl<>(this.gsReturnDao.queryAllByLimit(gsReturn, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int insert(String orderId,int returnAmount,String returnCause){
        return this.gsReturnDao.insert(orderId,returnAmount,returnCause);

    }

    public GsReturn queryByTime(Date applyDateTime){
        return this.gsReturnDao.queryByTime(applyDateTime);
    }

    public  int refuseReturn(String orderId){
        return gsReturnDao.refuseReturn(orderId);
    }

    public int agreeReturn(String orderId){
        return gsReturnDao.agreeReturn(orderId);
    }


    public List<GsReturn> queryByReturnState(String returnState){
        return this.gsReturnDao.queryByReturnState(returnState);
    }
    public GsReturn queryByOrderId(String orderId){
       return this.gsReturnDao.queryByOrderId(orderId);
    }

    @Override
    public List<GsReturn> queryAll() {
        return this.gsReturnDao.queryAll();
    }


    /**
     * 修改数据
     *
     * @param gsReturn 实例对象
     * @return 实例对象
     */
    @Override
    public GsReturn update(GsReturn gsReturn) {
        this.gsReturnDao.update(gsReturn);
        return this.queryById(gsReturn.getReturnId());
    }

    /**
     * 通过主键删除数据
     *
     * @param returnId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer returnId) {
        return this.gsReturnDao.deleteById(returnId) > 0;
    }
}
